package org.phone.web.controller;

import org.phone.manager.entity.CompanyInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/companyinfo")
public class CompanyController extends ParentController {

	@RequestMapping(method = RequestMethod.GET)
	public String showCompanyInfo(Model model) {
		CompanyInfo companyInfo = (CompanyInfo) dao.getEntity(CompanyInfo.class, 1);
		if (companyInfo == null) {
			model.addAttribute("companyInfo", new CompanyInfo());
		} else {
			model.addAttribute("companyInfo",companyInfo);
		}
		return "companyinfo";
	}

	@RequestMapping(method = RequestMethod.POST, params = "upDate")
	public String upDateCompanyInfo(CompanyInfo companyInfo) {
		dao.saveOrUpdateEntity(companyInfo);
		return "redirect:/home";
	}
}
